import numpy as np
import pandas as pd

# read
url="https://labfile.oss.aliyuncs.com/courses/906/los_census.csv"
df=pd.read_csv(url)
print(df)
df2=pd.read_excel('dataset.xlsx','Ligands')
print(df2)
df3=pd.read_html('http://www.pdbbind.org.cn/search.php')
print(df3)
# check
df.head()
df.tail(7)
df.describe()
array=df.values
print(type(array))
df.index
df.columns
df.shape
# choose
df.iloc[:3]
df.iloc[[1,3,5]]
df.iloc[:,1:4]
df.loc[0:2]
df.loc[[0,2,4]]
df.loc[:,'Total Population':'Total Males']
df.loc[[0,2],'Median Age':]
# delete
df.drop(labels=['Median Age','Total Males'],axis=1)
df.drop_duplicates()
df.dropna()
# detect
df=pd.DataFrame(np.random.rand(9,5),columns=list('ABCDE'))
df.insert(value=pd.Timestamp('2017-10-1'),loc=0,column='Time')
df.iloc[[1,3,5,7],[0,2,4]]=np.nan
df.iloc[[2,4,6,8],[1,3,5]]=np.nan
print(df.isna())
print(df.notna())
# fill
print(df.fillna(0))
print(df.fillna(method='pad'))
print(df.fillna(method='bfill'))
df.iloc[[3,5],[1,3,5]]=np.nan
print(df.fillna(method='pad'))
print(df.fillna(method='pad',limit=1))
print(df.fillna(df.mean()['C':'E']))
# insert
df=pd.DataFrame(dict(A=[1.1,2.2,np.nan,4.5,5.7,6.9],
                     B=[0.21,np.nan,np.nan,3.1,11.7,13.2]))
print(df.interpolate())
print(df.interpolate(method='quadratic'))
print(df.interpolate('pchip'))
print(df.interpolate('akima'))
print(df.interpolate('barycentric'))
